package com.lp;

import java.sql.*;
import java.util.UUID;

public class test {
    private static final String ORACLE_URL = "jdbc:oracle:thin:@10.1.21.254:12345:ORCL";
    private static final String ORACLE_USER = "YJGLJ_FXJC_1";
    private static final String ORACLE_PASSWORD = "baosight123";

    public static void main(String[] args) throws SQLException{

        String insertSQL = "INSERT INTO YJGLJ_FXJC.TB_REAL_MON_DATA03 (st_data_id, target_code, st_data, collect_time) VALUES (?, ?, ?, ?)"; // 修改为你的Oracle表结构

        try (Connection oracleConnection = DriverManager.getConnection(ORACLE_URL, ORACLE_USER, ORACLE_PASSWORD);
             PreparedStatement oraclePreparedStatement = oracleConnection.prepareStatement(insertSQL)){
            String uuid = UUID.randomUUID().toString().replace("-","");
            // 设置Oracle插入语句的参数
            oraclePreparedStatement.setString(1, uuid);
            oraclePreparedStatement.setString(2, "1");
            oraclePreparedStatement.setDouble(3, 12.65);
            oraclePreparedStatement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
//            oraclePreparedStatement.executeUpdate();
            System.out.println("Data synchronized successfully." + uuid);

//            // 从MySQL结果集中获取数据
//            List<TbRealMonData03BO> list = new ArrayList<>();
//            TbRealMonData03BO info = new TbRealMonData03BO();
//            info.setSt_data_id(UUID.randomUUID().toString().replace("-",""));
//            info.setTarget_code("1");
//            info.setSt_data(12.65);
//            info.setCollect_time(new Timestamp(System.currentTimeMillis()));
//            list.add(info);
//
//            for (TbRealMonData03BO tbRealMonData03BO : list) {
//                // 从MySQL结果集中获取数据
//                String column1Data = UUID.randomUUID().toString().replace("-","");  // 修改为你的字段名称
//                String column2Data = tbRealMonData03BO.getTarget_code();  // 修改为你的字段名称
//                Double column3Data = tbRealMonData03BO.getSt_data();  // 修改为你的字段名称
//                Timestamp column4Data = tbRealMonData03BO.getCollect_time();  // 修改为你的字段名称
//
//                // 设置Oracle插入语句的参数
//                oraclePreparedStatement.setString(1, column1Data);
//                oraclePreparedStatement.setString(2, column2Data);
//                oraclePreparedStatement.setDouble(3, column3Data);
//                oraclePreparedStatement.setTimestamp(4, column4Data);
//
//                // 执行插入
//                oraclePreparedStatement.executeUpdate();
//            }
//
//            // 执行批量插入
////            int[] affectedRecords = oraclePreparedStatement.executeBatch();
//            System.out.println("Data synchronized successfully. Number of records affected: ");
        } catch (SQLException e) {
            e.printStackTrace();
            throw e;
        }
    }
}
